package com.matace.keychain.presentation.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.matace.keychain.domain.TermsUseCase;

/**
 * 条款界面的ViewModel
 * 负责处理条款相关的业务逻辑和UI状态管理
 */
public class TermsViewModel extends ViewModel {
    private final TermsUseCase termsUseCase;
    // 条款文本数据
    private final MutableLiveData<String> termsText = new MutableLiveData<>();
    // 是否同意条款的状态数据
    private final MutableLiveData<Boolean> agreed = new MutableLiveData<>(false);

    /**
     * 构造函数
     * @param termsUseCase 条款用例
     */
    public TermsViewModel(TermsUseCase termsUseCase) {
        this.termsUseCase = termsUseCase;
        termsText.setValue(termsUseCase.getTermsText());
    }

    /**
     * 获取条款文本的LiveData
     * @return 条款文本的LiveData
     */
    public LiveData<String> getTermsText() {
        return termsText;
    }

    /**
     * 获取是否同意条款的LiveData
     * @return 是否同意条款的LiveData
     */
    public LiveData<Boolean> getAgreed() {
        return agreed;
    }

    /**
     * 同意条款
     * 调用用例中的同意条款方法，并更新UI状态
     */
    public void agreeTerms() {
        termsUseCase.agreeTerms();
        agreed.setValue(true);
    }
}